package views;

import android.content.Context;
import android.support.annotation.DrawableRes;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.zx.theline.R;

/**
 * Created by Ren on 2017/6/5.
 */

public class MoreItem extends LinearLayout {

    ImageView iv;
    TextView tv;
    //标题
    String title;
    //标题图片
    int ResId;
    MoreItemClickLinten mMoreItemClickLinten;

    public MoreItem(Context context,String title,@DrawableRes int ResId,MoreItemClickLinten clickLinten) {
        super(context);
        this.title=title;
        this.ResId=ResId;
        this.mMoreItemClickLinten=clickLinten;
        initView();
    }

    private void initView() {
        View view=inflate(getContext(), R.layout.more_item,null);
        iv= (ImageView) view.findViewById(R.id.imageview);
        tv= (TextView) view.findViewById(R.id.textview);
        tv.setText(title);
        iv.setBackgroundResource(ResId);

        addView(view);
        //给item设置click事件
        view.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mMoreItemClickLinten.moreItemClickLinten();
            }
        });
    }

    public void setTile(String title){
        tv.setText(title);
    }

    public void setImage(@DrawableRes int resId){
        iv.setBackgroundResource(resId);
    }


    public interface MoreItemClickLinten{
         void moreItemClickLinten();
    }
}
